﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HTTT.AD;
using System.Configuration;
using HTTT.DTO;
using HTTT.Bussiness;
using HTTT.Utilities;

namespace HTTT.admin
{
    public partial class OUSyn : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CheckPermission();
            }
        }
        private void CheckPermission()
        {
            if (!Page.User.IsInRole(Constants.ROLE_SUPER_ADMINISTRATOR)
                 && !Page.User.IsInRole(Constants.ROLE_ADMINISTRATOR))
            {
                Response.Redirect("/admin/AccessDenied.aspx");
            }
            if (!Page.User.IsInRole(Constants.ROLE_SUPER_ADMINISTRATOR))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "Message", Common.FormatMsgThenRedirect("Bạn không có quyền", "/admin/AdminIndex.aspx"), true);
            }
        }

        protected void btnGet_Click(Object sender, EventArgs e)
        {
            ADManager Manager = new ADManager(
               ConfigurationManager.AppSettings["LDAPDomain"]
               , ConfigurationManager.AppSettings["LDAPPath"]
               , ConfigurationManager.AppSettings["LDAPUser"]
               , ConfigurationManager.AppSettings["LDAPPassword"]);
            List<OUDTO> ListOU = Manager.GetOUAllList();
            HT_OUBO BO = new HT_OUBO();

            ReturnValue<bool> result = BO.SynNewData(ListOU);
            ClientScript.RegisterStartupScript(this.GetType(), "Message", Common.FormatAlertMsg(result.Msg), true);
        }
    }
}